package com.qaml.mes.device.controller;


import com.earth.output.OutputMessage;
import com.qaml.mes.device.api.HolidayApplyService;
import com.qaml.mes.device.dto.eqp.HolidayApplyDTO;
import com.qaml.mes.device.dto.eqp.HolidayApplyOrderIdDTO;
import com.qaml.mes.device.vo.eqp.HolidayApplyAuthVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 假日申请表 前端控制器
 * </p>
 *
 * @author leikai
 * @since 2024-03-04
 */
@Api(tags = "假日申请")
@RestController
@RequestMapping("/holiday/apply")
public class HolidayApplyController {

    @Resource
    private HolidayApplyService holidayApplyService;

    /**
     * 创建假期申请
     */
    @PostMapping("/createHolidayApply")
    @ApiOperation(value = "创建假期申请(App)", notes = "创建假期申请")
    public OutputMessage<String> createHolidayApply(@RequestBody @Validated HolidayApplyDTO holidayApplyDTO) {
        holidayApplyService.createHolidayApply(holidayApplyDTO);
        return OutputMessage.success("创建假期申请成功!");
    }

    /**
     * 获取假期申请详情
     */
    @PostMapping("/getHolidayApply")
    @ApiOperation(value = "获取假期申请详情(App)", notes = "获取假期申请详情")
    public OutputMessage<HolidayApplyAuthVO> getHolidayApplyById(@RequestBody HolidayApplyDTO holidayApplyDTO) {
        return OutputMessage.success(holidayApplyService.getHolidayApply(holidayApplyDTO));
    }

    /**
     * 批准假期申请
     */
    @PostMapping("/recheckCommit")
    @ApiOperation(value = "批准假期申请(App)", notes = "批准假期申请")
    public OutputMessage<String> recheckCommit(@RequestBody @Validated HolidayApplyOrderIdDTO holidayApplyOrderId) {
        holidayApplyService.passCommit(holidayApplyOrderId);
        return OutputMessage.success("批准假期申请成功!");
    }

    /**
     * 驳回假期申请
     */

    @PostMapping("/archiveTurnDown")
    @ApiOperation(value = "驳回假期申请(App)", notes = "驳回假期申请")
    public OutputMessage<String> archiveTurnDown(@RequestBody @Validated HolidayApplyOrderIdDTO holidayApplyOrderId) {
        holidayApplyService.overruledCommit(holidayApplyOrderId);
        return OutputMessage.success("驳回假期申请成功!");
    }
}
